home *** CD-ROM | disk | FTP | other *** search
/ IRIX Installation Tools & Overlays 2002 November / SGI IRIX Installation Tools & Overlays 2002 November - Disc 4.iso / dist / infosearch.idb / usr / lib / infosearch / bin / book2html.z / book2html
Text File  |  2002-10-15  |  3KB  |  145 lines

  1. #!/usr/bin/perl
  2. #
  3. # Copyright 1996-2002, Silicon Graphics, Inc.
  4. # All Rights Reserved.
  5. #
  6. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  7. # the contents of this file may not be disclosed to third parties, copied or
  8. # duplicated in any form, in whole or in part, without the prior written
  9. # permission of Silicon Graphics, Inc.
  10. #
  11. # RESTRICTED RIGHTS LEGEND:
  12. # Use, duplication or disclosure by the Government is subject to restrictions
  13. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  14. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  15. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  16. # rights reserved under the Copyright Laws of the United States.
  17. #
  18. #  --------
  19. #  book2html 
  20. #  ---------
  21. #  filter books
  22. #
  23. #  Usage:
  24. #       book2html [-r <root>] [-db <db>] [-h <highlight>] /<std_pth>/<file>
  25. #
  26. #  requires perl5 and book2html.pl
  27. #
  28.  
  29. $| = 1;
  30.  
  31. use strict;
  32.  
  33. # globals
  34. #
  35. package InfoSearch;
  36.  
  37. $InfoSearch::COLLECTION = $ENV{'COLLECTION'};
  38. $InfoSearch::_TR        = $ENV{'TOOLROOT'};
  39. $InfoSearch::_WEB       = ($ENV{'REQUEST_METHOD'} ne '' ? 1 : 0);
  40. $InfoSearch::_DB        = 'bks';
  41.  
  42. require 'book2html.pl';
  43.  
  44. &main(@ARGV);
  45. exit(0);
  46.  
  47.  
  48.  
  49. #######################################################################
  50. #
  51. # void main()
  52. #
  53. #######################################################################
  54.  
  55. sub main {
  56.  
  57.   my(@argv) = @_;
  58.   unless ($argv[0]) {
  59.         print "book2html: no arguments" if (${InfoSearch::_WEB} == 0);
  60.         return;
  61.   }
  62.  
  63.   # root = /d1
  64.   # pth  = /usr/share/Insight/library/SGI_bookshelves
  65.   #
  66.   my($fname, $bk_root, $bk_pth, $srch_str) = '';
  67.   my($i) = 0;
  68.   while($i < (@argv + 0)) {
  69.  
  70.         if ($argv[$i] eq "-h") {
  71.  
  72.            splice(@argv, $i, 1);
  73.            if( $argv[$i] ne '' ) {
  74.                $srch_str = $argv[$i];
  75.                splice(@argv, $i, 1);
  76.            }
  77.  
  78.         } elsif ($argv[$i] eq "-r") { 
  79.  
  80.            splice(@argv, $i, 1);
  81.            if( $argv[$i] ne '' ) {
  82.                $bk_root = $argv[$i];
  83.                splice(@argv, $i, 1);
  84.            }
  85.  
  86.         } elsif ($argv[$i] eq "-p") {
  87.  
  88.            splice(@argv, $i, 1);
  89.            if( $argv[$i] ne '' ) {
  90.                $bk_pth = $argv[$i];
  91.                splice(@argv, $i, 1);
  92.            }
  93.  
  94.         } elsif ($argv[$i] eq "-db") {
  95.  
  96.            splice(@argv, $i, 1);
  97.            if( $argv[$i] ne '' ) {
  98.                $InfoSearch::_DB = $argv[$i];
  99.                splice(@argv, $i, 1);
  100.            }
  101.  
  102.         } else {
  103.            $i++;
  104.         }
  105.   }
  106.  
  107.   # take whatever is left
  108.   #
  109.   $fname = join(' ', @argv);
  110.  
  111.   #  Set the path for security and taint checking.
  112.   #
  113.   $ENV{'PATH'} = "${InfoSearch::_TR}/usr/sbin:" .
  114.                  "${InfoSearch::_TR}/usr/bin:"  .
  115.                  "${InfoSearch::_TR}/bin:/usr/sbin:/usr/bin:/bin";
  116.  
  117.   # check (again!)
  118.   #
  119.   my($OK_CHARS) = "-a-zA-Z0-9_.*:;\+\/τ";
  120.   $fname =~ s/[^$OK_CHARS]//go;
  121.   if( $fname =~ /\.\./ || $fname =~ /^\/etc/ || $fname =~ /\&/ 
  122.       ||
  123.       $fname =~ /\;/ || $fname =~ /\|/ || $fname =~ /\,/
  124.       ||
  125.       $fname =~ /\>/ || $fname =~ /\</ ) {
  126.  
  127.       print "book2html: Illegal document access" if (${InfoSearch::_WEB} == 0);
  128.       return;
  129.   }
  130.  
  131.   $bk_pth  =~ s/[^$OK_CHARS]//go;
  132.   $bk_root =~ s/[^$OK_CHARS]//go;
  133.  
  134.   # default path
  135.   #
  136.   if( $bk_pth eq '' ) {
  137.       $bk_pth = '/usr/share/Insight/library/SGI_bookshelves';
  138.   }
  139.  
  140.   &book2html($bk_root, $bk_pth, $fname, $srch_str);
  141.  
  142.   return;
  143. }
  144.  
  145.